<!DESCRIPTION>A script that checks the number of words in a form box, and if it exceeds the predetermined number, cancels the form submission, and asks the surfer to re-enter data. This script requires NS 3.x, 4.x, or IE 4.x to function-all other browsers will simply not participate in the word checking.
<!/DESCRIPTION>
<!CATEGORY>form and form validation<!/CATEGORY>
<!SCRIPT>
<!-- START OF SCRIPT -->
<script>
<!--
function checkwords(cur){
//change max # of words to determine below
var maxwords=10
if (document.images){
var temp=cur.words.value.split(" ")
if (temp.length>maxwords){
alert("Please restrain your input to 10 or less words!")
return false
}
}
}
//-->
</script>
<form onsubmit="return checkwords(this)">
<strong>In 10 words or less, please tell us your qualifications:</strong><br><textarea rows="5" cols="38" name="words"></textarea>
<br><input type="submit" value="Submit!">
</form>
<!-- END OF SCRIPT -->
<!/SCRIPT>
<!PREVIEW>
<!-- START OF SCRIPT -->
<script>
<!--
function checkwords(cur){
//change max # of words to determine below
var maxwords=10
if (document.images){
var temp=cur.words.value.split(" ")
if (temp.length>maxwords){
alert("Please restrain your input to 10 or less words!")
return false
}
}
}
//-->
</script>
<form onsubmit="return checkwords(this)">
<strong>In 10 words or less, please tell us your qualifications:</strong><br><textarea rows="5" cols="38" name="words"></textarea>